package com.bizdk.fastfx.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bizdk.fastfx.domain.entity.Patient;
import com.bizdk.fastfx.domain.mapper.PatientMapper;
import com.bizdk.fastfx.model.PatientModel;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class PatientService extends ServiceImpl<PatientMapper, Patient> {

    public ObservableList<PatientModel> listModel() {
        List<Patient> list = this.list();
        if (null == list || list.isEmpty()) {
            return FXCollections.observableArrayList();
        }

        List<PatientModel> collect = list.stream().map(PatientModel::new).collect(Collectors.toList());
        return FXCollections.observableArrayList(collect);
    }

    public void addModel(PatientModel model) {
        this.save(model.toPatient());
    }

    public void updateModel(PatientModel model) {
        this.updateById(model.toPatient());
    }

    public void delModel(PatientModel model) {
        this.removeById(model.getId());
    }
}
